package com.gopay.common.user.dao.impl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.constants.cust.UserInfoConstants;
import com.gopay.common.domain.UserInfo;
import com.gopay.common.user.dao.UserInfoDAO;

/**
 * 用户读写dao（已作废，但存量代码在引用，不能删）
 * @UserInfoDAOImpl_Bak.java
 * @author fanghw
 * @2016年10月13日 下午5:27:15  www.gopay.com.cn Inc.All rights reserved.
 */
@Repository("commonQueryUserDao")
public class UserInfoDAOImpl_Bak extends BaseDAOImpl<UserInfo, Serializable> implements UserInfoDAO {

    protected Logger logger = LoggerFactory.getLogger(UserInfoDAOImpl.class);
    
    @Override
    public List<UserInfo> queryUsersByCondition(Map<String, Object> params) {
        String hql = "from UserInfo t where 1=1";
        for( Map.Entry<String, Object> entry : params.entrySet() ){
            hql += " AND "+entry.getKey()+"=:"+entry.getKey();
        }
        return this.findByHql(hql, params);
    }

    @Override
    public List<UserInfo> queryUsersByCreateTs(String startTime, String endTime) {
        String hql = "from UserInfo t where 1=1 AND t.createdTs >= to_timestamp('"+startTime+"' , 'yyyy-MM-dd HH24:MI:ss.ff') AND t.createdTs <= to_timestamp('"+endTime+"' , 'yyyy-MM-dd HH24:MI:ss.ff') order by t.createdTs asc";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userType", UserInfoConstants.USER_TYPE_PERSON);
        params.put("userStat", UserInfoConstants.USER_STAT_NORMAL);
        params.put("userResource", "WALLET_APP");
        for( Map.Entry<String, Object> entry : params.entrySet() ){
            hql += " AND t."+entry.getKey()+"=:"+entry.getKey();
        }
        return this.findByHql(hql, params);
    }

    @Override
    public List<UserInfo> getByCustId(String custId) {
        String hql = "from UserInfo where custId=:custId and userStat!=:userStat ";
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("custId", custId);
        paramMap.put("userStat", UserInfoConstants.USER_STAT_CANCEL);
        List<UserInfo> list = this.findByHql(hql, paramMap);
        return list.isEmpty() ? null : list;
    }
    /**
     * add by tangyang at 20171020
     */
    @Override
    public UserInfo getByCustIdAndOperId(String custId, String operId){
    	/*
    	 * UserInfoDAOImpl中增加此方法，所以UserInfoDAO中新增此接口。
    	 * 本类中实现了UserInfoDAO接口，所以要实现所有接口方法
    	 */
    	return null;
    }
}
